package cn.abellflower.lamba;

import lombok.Data;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author gbzdyf@126.com
 * @Create: 2019/9/10 16:20
 */
public class Demo {
    public static void main(String[] args) {

        List<User> users = new ArrayList<>();
        User user;
        for (int i = 0; i < 5; i++) {
            user = new User();
            user.setName("name_" + i);
            user.setAge(i);
            users.add(user);
        }
        System.out.println(users);

        Map<String, User> collect = users.stream().collect(Collectors.toMap(User::getName, u -> u));
        List<User> collect1 = users.stream().sorted(Comparator.comparing(User::getName).reversed()).collect(Collectors.toList());
        System.out.println(collect1);
    }
}

@Data
class User{
    private String name;
    private int age;
}